<template>
    <div>
        <Form :label-width="100" inline>
            <Form-item label="数据类别">
                <c-dict-select v-model="queryParam.mmwg0001" dictCode="mmwg"/>
            </Form-item>
            <Form-item label="属地区划">
                <c-dict-select v-model="queryParam.mmwg0002" dicType="service"
                            dictService="/api/ac/subsistence/extSysDictService/getSs01001List" clearable
                            style="width:150px"/>
            </Form-item>
            <Row class="button_row">
                <span style="float: left;">
                  <Button type="primary" @click="handleAdd()">录入</Button>
                </span>
                <span style="float: right;">
                    <Button type="primary" @click="searchQuery">查询</Button>
                    <Button type="primary" class="button_item_left" @click="searchReset">重置</Button>
                </span>
            </Row>
        </Form>
        <Modal v-model="visible" :title="title" width="600" style="position:relative;">
            <Form ref="formData" :model="formData" :label-width="150" :rules="rules" :disabled="disableSubmit">
                <FormItem label="数据类别" prop="mmwg0001">
                    <c-dict-select v-model="formData.mmwg0001" dictCode="mmwg" placeholder="请选择数据类别"/>
                </FormItem>
                <Form-item label="属地区划" prop="mmwg0002">
                    <c-dict-select v-model="formData.mmwg0002" dicType="service"
                                   dictService="/api/ac/subsistence/extSysDictService/getSs01001List" clearable
                                   placeholder="请选择属地区划"
                                   style="width:150px"/>
                </Form-item>
                <FormItem label="金额" prop="mmwg0003">
                    <InputNumber v-model="formData.mmwg0003" placeholder="请输入金额" style="width: 200px" :max="99999999"  :min="0"/>
                </FormItem>
            </Form>
            <div slot="footer">
                <Button type="text" size="large" @click="visible = false">取消</Button>
                <template v-if="!disableSubmit">
                    <Button type="primary" size="large" @click="handleSubmit('formData')">确定</Button>
                </template>
            </div>
        </Modal>
        <div class="table_div">
            <vxe-table border
                       resizable
                       row-id="id"
                       :row-key="true"
                       show-overflow="tooltip"
                       highlight-hover-row
                       align="center"
                       header-align="center"
                       ref="xTree"
                       :loading="Loading"
                       :data="tableData">
                <vxe-table-column field="mmwg0001_name" title="数据类别" align="center" fixed="left"/>
                <vxe-table-column field="azaa0002" title="属地区划" align="center" fixed="left"/>
                <vxe-table-column field="mmwg0003" title="金额" align="center" />
                <vxe-table-column field="" title="操作" width="200" fixed="right">
                    <template v-slot="{ row }">
                        <Button type="warning" size="small" style="margin-right: 5px" @click="handleEdit(row)">编辑</Button>
                        <Button type="success" size="small" style="margin-right: 5px" @click="handleDetail(row)">详情</Button>
                        <Button type="error" size="small" style="margin-right: 5px" @click="handleDelete(row.id)">删除</Button>
                    </template>
                </vxe-table-column>
            </vxe-table>
            <Page :total="dataCount" :page-size="pageSize" show-total class="paging"
                  @on-change="handleTableChange" :current="pageNo"></Page>
        </div>
    </div>
</template>

<script>
    import {postAction} from '@/api/request'
    import {CommonMixin} from '@/views/common/js/CommonMixin'

    export default {
        mixins: [CommonMixin],
        components: {},
        data() {
            return {
                rules: {
                    mmwg0001: [
                        {required: true, message: '请选择数据类别', trigger: 'blur'}
                    ],
                    mmwg0002: [
                        {required: true, message: '请选择属地', trigger: 'blur'}
                    ],
                    mmwg0003: [
                        {required: true, message: '请输入金额', trigger: 'blur', type: 'number'}
                    ],
                },
                fieldsToValidate02: ["mmwg0001", "mmwg0002", "mmwg0003"],
                tableData: [],
                Loading: false,
                url: {
                    list: "/api/ac/subsistence/ss06004Service/getPageList",
                    delete: "/api/ac/subsistence/ss06004Service/deleteData"
                },
                formData: {},
                queryParam: {},
                visible: false,
                dataCount: 0,
                pageSize: 10,
                modal: false,
                title: "",
                disableSubmit: false
            }
        },
        methods: {
            handleAdd() {
                this.$refs['formData'].resetFields();
                this.disableSubmit = false;
                let that = this;
                that.title = "要件配置录入"
                let record = {};
                that.visible = true
                that.formData = Object.assign({}, record)
            },
            handleDetail(row) {
                this.$refs['formData'].resetFields();
                let that = this;
                that.title = "详情";
                that.disableSubmit = true;
                let record = row;
                if (record.id) {
                    that.visible = true
                    that.formData = Object.assign({}, record)
                } else {
                    that.visible = false
                }
            },
            handleEdit(row) {
                this.$refs['formData'].resetFields();
                this.disableSubmit = false;
                let that = this;
                that.title = "要件配置编辑"
                let record = row;
                if (record.id) {
                    that.visible = true
                    that.formData = Object.assign({}, record)
                } else {
                    that.visible = false
                }
            },
            handleSubmit(name) {
                let that = this;
                let validate = true;
                let err_msg = [];
                for (let item of that.fieldsToValidate02) {
                    that.$refs[name].validateField(item, (error) => {
                        if (error) {
                            validate = false;
                            err_msg.push(that.rules[item][0].message);
                        }
                    })
                }
                if (validate) {
                    let that = this;
                    that.Loading = true;
                    let url = "/api/ac/subsistence/ss06004Service/insertData";
                    if (this.formData.id) {
                        url = "/api/ac/subsistence/ss06004Service/updateData";
                    }
                    postAction(url, this.formData).then((res) => {
                        if (res.data.errcode != 0) {
                            this.$Message.error(res.data.errmsg);
                        } else {
                            this.modalFormOk();
                            this.visible = false;
                        }
                    }).finally(() => {
                        that.Loading = false;
                    });
                } else {
                    that.$Message.error(err_msg[0]);
                    return;
                }
                // })
            }
        },
        created() {
            this.loadData();
        },
    }
</script>
<style scoped>
    /*.paging {*/
    /*    float: right;*/
    /*    margin-top: 10px;*/
    /*}*/

    /*/deep/ .ivu-upload-list {*/
    /*    display: none;*/
    /*}*/
    /deep/ .ivu-form-item-error-tip {
        display: none;
    }

    .itemStyle {
        width: 180px
    }

    .head-img1 {
        height: 200px;
        width: 250px;
        margin-top: 15px;
    }

    .head-img {
        height: 200px;
        width: 250px;
    }

    .imgBackColor {
        background-color: WhiteSmoke;
        height: 250px;
    }

    .positiveTDiv {
        height: 240px;
        width: 75px;
        line-height: 240px;
        background-color: #7CCD7C;
        margin-bottom: 10px;
        color: white;
        font-size: 14px;
        font-weight: 700;
    }
</style>
